﻿using System;
using System.Text;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(WebDemo.MyStartup))]
//[assembly: OwinStartup(typeof(WebDemo.MyStartup), "MyConfiguration")]

namespace WebDemo
{
    /// <summary>
    /// 默认约定的启动类
    /// </summary>
    public class Startup
    {
        /// <summary>
        /// 默认约定启动函数
        /// </summary>
        public void Configuration(IAppBuilder app)
        {
            app.UseErrorPage();
            app.Run(context =>
            {
                if (context.Request.Path.ToString() == "/fail")
                {
                    throw new Exception("This is Owin Diagnostics Test.");
                }

                context.Response.ContentType = "text/plain;charset=UTF-8";
                return context.Response.WriteAsync(" => Startup --> Configuration");
            });
        }
    }


    /// <summary>
    /// 自定义约定启动类
    /// </summary>
    public class MyStartup
    {
        /// <summary>
        /// 默认约定启动函数
        /// </summary>
        public void Configuration(IAppBuilder app)
        {
            app.UseErrorPage();
            app.Run(context =>
            {
                if (context.Request.Path.ToString() == "/fail")
                {
                    throw new Exception("This is Owin Diagnostics Test.");
                }
                context.Response.ContentType = "text/plain;charset=UTF-8";
                return context.Response.WriteAsync(" => [MyStartup] --> Configuration");
            });
        }

        /// <summary>
        /// 自定义约定启动函数
        /// </summary>
        public void MyConfiguration(IAppBuilder app)
        {
            app.Run(context =>
            {
                context.Response.ContentType = "text/plain;charset=UTF-8";
                return context.Response.WriteAsync(" =>  [MyStartup] --> [MyConfiguration]");
            });
        }
    }
}
